<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>公司审核</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
 <script src="${pageContext.request.contextPath}/static/js/global.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
         .jqGrid_wrapper{
			*+margin-left:270px;
		}  
    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
    <div class="jqGrid_wrapper">
        <div id="jqGrid_operation" class="jg-grid">
            <h1>公司审核</h1>
            <div class="jqGrid_operation" id="action"></div>
        </div>
        <table id="jqGrid"></table>
        <div id="jqGrid_paper"></div>
    </div>
</div>
<script>
    $(document).ready(
            function () {

                $.jgrid.defaults.styleUI = "Bootstrap";
                $("#jqGrid").jqGrid(
                        {
                            url: "${pageContext.request.contextPath}/admin/tagent_auditList.action",
                            mtype: 'POST',
                            datatype: "json",
                            height:450,
// 							autoheight:	true,
// 							width:window.innerWidth,
                            autowidth: true,
                            shrinkToFit: true,
                            rowNum: 10,
                            rowList: [10, 20, 30],
                            colNames: ['序号', '申请时间','所属区域', '公司名称', '帐号', '联系人',
                                '联系方式 ', '地址 ', '附件', '状态', '审核人', '审核时间', '备注', '操作'],
                            colModel: [{
                                name: "SID",
                                index: "SID",
                                key: true,
                                hidden: true
                            }, {
                                name: 'REQTIME',
                                index: 'REQTIME',
                                width: 80
                            }, {
                                name: 'DESCRIBED',
                                index: 'DESCRIBED',
                                width: 80
                            }, {
                                name: 'AGTNAME',
                                index: 'AGTNAME',
                                width: 80
                            },{
                                name: 'ADMINUSER',
                                index: 'ADMINUSER',
                                width: 80
                            },{
                                name: 'AGTCONTACT',
                                index: 'AGTCONTACT',
                                width: 50
                            },{
                                name: 'AGTTEL',
                                index: 'AGTTEL',
                                width: 80
                            },{
                                name: 'ADDRESS',
                                index: 'ADDRESS',
                                width: 80
                            },{
                                name: 'AGTATTR',
                                index: 'AGTATTR',
                                width: 50,
                                formatter: function (cellvalue, options, rawObject) {
                                    if(!cellvalue){
                                    	return '无附件';
                                    }else if(cellvalue == '-1'){
                                     	return '';
                                    }else{
	                                	return '<a href="javascript:void(0);" onclick="showpic(\''+cellvalue+'\');">查看详情 </a>';
                                    }
                                	}
                            },{
                                name: "STATUS",
                                index: "STATUS",
                                width: 40,
                                formatter: "select",
                                editoptions: {value: "-1:;0:待审核;1:审核通过;2:审核拒绝;3:候审;"}
                            },{
                                name: 'AUSERNAME',
                                index: 'AUSERNAME',
                                width: 50
                            },{
                                name: 'ATIME',
                                index: 'ATIME',
                                width: 80
                            },{
                                name: 'COMM',
                                index: 'COMM',
                                width: 50
                            },{
                                name: 'STATUS',
                                index: 'STATUS',
                                width: 160,
                                formatter: function (cellvalue, options, rawObject) {
                                 switch (cellvalue) {
                                     case "0":
                                     case "3":
                                       return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="拒绝 " onclick="refuse('
                                                     + rawObject.SID + ',2)"/><input type="button" style="padding: 2px 10px" class="btn btn-success" value="候审" onclick="refuse('
                                                     + rawObject.SID + ',3)"/><input type="button" style="padding: 2px 10px" class="btn btn-success" value="通过" onclick="audit('
                                                     + rawObject.SID + ',1)"/>';
                                     	break;
                                     case "1":
                                         return "审核通过";
                                         break;
                                     case "2":
                                         return "审核拒绝";
                                         break;
                                     case "-1":
                                         return "";
                                         break;
                                 	}
                             	}
                            }],
                            sortname: 'sid',
                            sortorder:'desc',
                            rownumbers: true,
                            jsonReader: {
                                root: 'rows',
                                page: "page",
                                total: 'total',
                                records: "records",
                                repeatitems: false
                            },
                            pager: "#jqGrid_paper",
                            viewrecords: true,
                            multiselect: true,
                            hidegrid: false,
                            loadComplete: function(){
                        		var re_records = Number($("#jqGrid").getGridParam('records'));
                        		var page = Number($("#jqGrid").getGridParam('page'));
                        		var rows=Number($("#jqGrid").getGridParam('rowNum'));
                        		var num = re_records-(page-1)*rows;
                        		if(num < rows)
                        		{
                        			for(var i=num;i<rows;i++){
                        				$("#jqGrid").jqGrid("addRowData",(i+1),
                                				{ "SID":"", "REQTIME":"", "DESCRIBED":"", "AGTNAME":"", "ADMINUSER":"","AGTCONTACT":"","AGTTEL":"","ADDRESS":"","AGTATTR":"-1","STATUS":"-1","AUSERNAME":"","ATIME":"","COMM":"","STATUS":"-1"}
                        				,"");
                        			}
                        			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
                        		}
                        	}
                        });
            });

    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    
//     function audit(sid,status){
// 	   	$.post("${pageContext.request.contextPath}/admin/tagent_audit.action", {
// 	   		'sid': sid,
//          	'status': status
//          }, function (result) {
//              result = JSON.parse(result)
//              if (result.code == 1 || result.code == 2) {
//                  refreshGrid();
//              } 
//              layer.alert(result.msg);
//          });
//    	 }
    
 	
 	 function showpic(content) {
         var html = '<img style="margin-left: -18px;" width="960px" src="' + content + '" alt="营业执照"/>';
         layer.open({
             title: '',
             btn: 0,
             area: ['960px', '95%'],
             content: html
         });
     }
 	function audit(sid,status){
    	layer.open({
            type: 2,
            title: '<strong>合作方分配</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['800px', '330px'],
            content: '${pageContext.request.contextPath}/admin/tagent_agree.action?sid='
            + sid+'&status='+status,
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var options = {
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.code == 1) {
                            layer.alert(data.msg, function () {
                                layer.closeAll();
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                        refreshGrid();
                    }
                };
                var appSid = $("#layui-layer-iframe" + index).contents().find("#appSid").val();
                if(appSid != ''){
	                $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
	                $("#layui-layer-iframe" + index).contents().find("#form").submit();
                }else{
                	alert("APP必须选择！");
                }
            }
        });
    }
 	function refuse(sid,status){
    	layer.open({
            type: 2,
            title: '<strong>拒绝原因</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['780px', '330px'],
            content: '${pageContext.request.contextPath}/admin/tagent_refuse.action?sid='
            + sid+'&status='+status,
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var options = {
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.code == 1) {
                            layer.alert(data.msg, function () {
                                layer.closeAll();
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                        refreshGrid();
                    }
                };
                $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
                $("#layui-layer-iframe" + index).contents().find("#form").submit();
            }
        });
    }
</script>
</body>
</html>
